package com.qzsl.platform.config;

import com.tac.base.enums.MessageCode;
import com.tac.base.exception.QzBizException;
import com.tac.base.model.SimpleMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.NoHandlerFoundException;
/**
 * @Description: 全局异常信息处理类
 * @Author Created by Alan
 **/
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {
    /**
     * API统一异常处理
     **/
    @ResponseBody
    @ExceptionHandler(value = Exception.class)
    public SimpleMessage<?> defaultErrorHandler(Exception e) {
        log.error("Exception",e);
        return SimpleMessage.fail("服务器异常，请稍后重试！");
    }

    @ResponseBody
    @ExceptionHandler(value = QzBizException.class)
    public SimpleMessage<?> qzBizErrorHandler(Exception e) {
        log.error("QzBizException",e);
        return SimpleMessage.fail(MessageCode.NORMAL_ERROR,e.getMessage());
    }

    @ResponseBody
    @ExceptionHandler(value = NoHandlerFoundException.class)
    public SimpleMessage<?> noHandlerFoundException(Exception e) {
        log.error("NoHandlerFoundException",e);
        return SimpleMessage.fail(MessageCode.NOT_FOUND_ERROR,"接口未定义");
    }

}
